package com.itheima.health.service.impl;

import com.itheima.health.dao.MenuDao;
import com.itheima.health.pojo.Menu;
import com.itheima.health.service.MenuService;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
@DubboService
@Slf4j
public class MenuServiceImpl implements MenuService {

    @Autowired
    private MenuDao menuDao;
    @Override
    public List<Menu> getMenuList(String username) {
        //获取主菜单
        List<Menu> parentMenu=menuDao.getParentMenu(username);
        //遍历主菜单，将二级子菜单加入父集
        for (Menu menu : parentMenu) {
            //获取父菜单的id
            Integer parentMenuId = menu.getId();
            List<Menu> childrenMenu=menuDao.getChildrenMenuByParentMenuId(parentMenuId,username);
            menu.setChildren(childrenMenu);
        }
        return parentMenu;
    }
}
